package com.dqyt.khjc.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.khjc.bean.FaceData;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.config.ReadConfig;
import com.dqyt.khjc.service.FaceDataService;
import com.dqyt.khjc.service.ReportPcService;
import com.dqyt.khjc.service.SamplePcService;
import com.dqyt.khjc.utils.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;




/**
 * 自动读取的测试数据结果控制器
 *
 * @author lifubo
 * @version 1.0
 * @date 创建时间：2019年8月20日 上午11:57:24
 * @parameter
 * @returnfileUpload
 * @since
 */
@RestController
public class FaceDataController {


    @Autowired
    private FaceDataService faceDataService;

    /**
     *新的气瓶的数据
     *
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value = "/api/uploadFaceData")
    public ResultMsg uploadFaceData(HttpServletRequest request, @RequestBody Map<String, String> map) {
        String data = map.get("data");
        ResultMsg resultMsg = faceDataService.uploadFaceData(request,data );
        return resultMsg;
    }


    /**
     * 气瓶的数据（老机器）
     *
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value = "/api/uploaQpold")
    public ResultMsg uploaQpold(HttpServletRequest request, @RequestBody Map<String, String> map) {
        String data = map.get("data");
        ResultMsg resultMsg = faceDataService.uploaQpold(request,data);
        return resultMsg;
    }



    /**
     * 呼吸器面罩（老的）
     *
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value = "/api/uploadBottleData")
    public ResultMsg uploadBottleData(HttpServletRequest request, @RequestBody Map<String, String> map) {
        String data = map.get("data");
        ResultMsg resultMsg = faceDataService.uploadBottleData(request,data);
        return resultMsg;
    }


//    /**
//     * 呼吸器面罩（新的）  *******  正式使用 请勿删除  ********
//     *
//     * @param request
//     * @param map
//     * @return
//     */
//    @RequestMapping(value = "/api/uploadMzNew")
//    public ResultMsg uploadMzNew(HttpServletRequest request, @RequestBody Map<String, String> map) {
//        String data = map.get("data");
//        ResultMsg resultMsg = null;
////        BufferedReader br = null;
////        String path = "a.json";
//        try {
////            br = new BufferedReader(new InputStreamReader(JsonTest.class.getClassLoader().getResourceAsStream(path)));
////            String line = br.readLine();
////            StringBuilder sb = new StringBuilder();
////            while (line != null) {
////                sb.append(line + "\r\n");
////                line = br.readLine();
////            }
////            System.out.println(sb.toString());
////            String data = sb.toString();
//         resultMsg = reportPcService.uploadMzNew(request,data);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return resultMsg;
//    }


    /**
     *呼吸器面罩（新的）  *******  正式使用 请勿删除  ********
     *
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value = "/api/uploadMzNew")
    public ResultMsg uploadMzNew(HttpServletRequest request, @RequestBody Map<String, String> map) {
        String data = map.get("data");
        ResultMsg resultMsg = faceDataService.uploadMzNew(request,data );
        return resultMsg;
    }



//    /**
//     * 呼吸器面罩（新的）   *************** 测试使用 ***************
//     *
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/api/uploadMzNew")
//    public ResultMsg uploadMzNew(HttpServletRequest request, String data) {
//        ResultMsg resultMsg = null;
//        StringBuffer strbuffer = new StringBuffer();
//        String pactFile = "D:\\daqingdata\\zmNew\\1111.json";
//        File myFile = new File(pactFile);//"D:"+File.separatorChar+"DStores.json"
//        if (!myFile.exists()) {
//            System.err.println("Can't Find " + pactFile);
//        }
//        try {
//            FileInputStream fis = new FileInputStream(pactFile);
//            InputStreamReader inputStreamReader = new InputStreamReader(fis, "UTF-8");
//            BufferedReader in = new BufferedReader(inputStreamReader);
//            String str;
//            while ((str = in.readLine()) != null) {
//                strbuffer.append(str);  //new String(str,"UTF-8")
//            }
//            in.close();
//            resultMsg = reportPcService.uploadMzNew(request,strbuffer.toString());
//        }catch (Exception e){
//
//        }
//        return resultMsg;
//    }

}